<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import goodsSku from '@/api/goods/goodsSku'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  goodsSku.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  goodsSku.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'goods_sku',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: goodsSku.getList,
  recycleApi: goodsSku.getRecycleList,
  add: {
    show: true,
    api: goodsSku.save,
    auth: ['goods:sku:save']
  },
  edit: {
    show: true,
    api: goodsSku.update,
    auth: ['goods:sku:update']
  },
  delete: {
    show: true,
    api: goodsSku.deletes,
    auth: ['goods:sku:delete'],
    realApi: goodsSku.realDeletes,
    realAuth: ['goods:sku:realDeletes']
  },
  recovery: {
    show: true,
    api: goodsSku.recoverys,
    auth: ['goods:sku:recovery']
  },
  import: {
    show: true,
    url: 'goods/sku/import',
    templateUrl: 'goods/sku/downloadTemplate',
    auth: ['goods:sku:import']
  },
  export: {
    show: true,
    url: 'goods/sku/export',
    auth: ['goods:sku:export']
  }
})

const columns = reactive([
  {
    title: "记录ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入记录ID"
    }
  },
  {
    title: "商品sku唯一标识 (由规格id组成)",
    dataIndex: "goods_sku_id",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入商品sku唯一标识 (由规格id组成)"
    }
  },
  {
    title: "商品ID",
    dataIndex: "goods_id",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品ID"
    }
  },
  {
    title: "规格图片ID",
    dataIndex: "image_id",
    formType: "upload",
    commonRules: {
      required: true,
      message: "请输入规格图片ID"
    },
    type: "image",
    multiple: false
  },
  {
    title: "商品sku编码",
    dataIndex: "goods_sku_no",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入商品sku编码"
    }
  },
  {
    title: "商品价格",
    dataIndex: "goods_price",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品价格"
    }
  },
  {
    title: "商品划线价",
    dataIndex: "line_price",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品划线价"
    }
  },
  {
    title: "当前库存数量",
    dataIndex: "stock_num",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入当前库存数量"
    }
  },
  {
    title: "商品重量(Kg)",
    dataIndex: "goods_weight",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入商品重量(Kg)"
    }
  },
  {
    title: "SKU的规格属性(json格式)",
    dataIndex: "goods_props",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入SKU的规格属性(json格式)"
    }
  },
  {
    title: "规格值ID集(json格式)",
    dataIndex: "spec_value_ids",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入规格值ID集(json格式)"
    }
  },
  {
    title: "商城ID",
    dataIndex: "store_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入商城ID"
    }
  },
  {
    title: "创建时间",
    dataIndex: "create_time",
    formType: "input",
    search: true,
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "更新时间",
    dataIndex: "update_time",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'goods:sku' } </script>